# Copyright 1999-2008 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $
inherit eutils rpm linux-info
#http://www.support-highpoint-tech.com/Main/HRM/Linux/WebGui-Linux-v1.4-10-091124.tgz
MY_PV="1.4-10"
MY_P="${PN}-${MY_PV}"
MY_PV2="${MY_PV}-091124"
MY_P2="WebGui-Linux-v${MY_PV2}"

DESCRIPTION="HighPoint RocketRaid WebGUI configuration tool."
HOMEPAGE="http://www.highpoint-tech.com"

SRC_URI="http://www.support-highpoint-tech.com/Main/HRM/Linux/${MY_P2}.tgz"

LICENSE=""

SLOT="0"

KEYWORDS="~amd64 ~x86"

IUSE="kernel_linux"

RESTRICT="strip mirror"

DEPEND="!sys-block/hptsvr"

RDEPEND="${DEPEND}"

pkg_setup() {
	if use kernel_linux ; then
		CONFIG_CHECK="SCSI_PROC_FS"
		linux-info_pkg_setup
	fi
}

src_unpack() {
	unpack ${A}
	cd "${WORKDIR}"

	if use amd64; then
		einfo "Removing i586 rpm from WORKDIR."
		rm "${WORKDIR}/${MY_P2}/${MY_P}.i386.rpm"
		einfo "Unpacking ${MY_P}.x86_64.rpm"
        rpm_unpack "${WORKDIR}/${MY_P2}/${MY_P}.x86_64.rpm"
	elif use x86; then
		einfo "Removing x86_64 rpm from WORKDIR."
        rm "${WORKDIR}/${MY_P2}/${MY_P}.x86_64.rpm"
		einfo "Unpacking ${MY_P}.i386.rpm"
        rpm_unpack "${WORKDIR}/${MY_P2}/${MY_P}.i386.rpm"
	fi
}

src_install() {
	exeinto /usr/bin
	doexe "${WORKDIR}/usr/bin/hptsvr"
	cp -R "${WORKDIR}/usr/share" "${D}/usr/" || die "Install failed!"
	dodoc "${WORKDIR}/${MY_P2}/README.txt"
	dodir /etc
	echo "hptmv6" > "${D}/etc/hptcfg"
	newinitd "${FILESDIR}/${P}-initd" hptsvr
	for dir in /usr/local/bin /usr/bin /usr/X11R6/bin; do
		if [ -f "${dir}/firefox" ] ; then
			dosym "${dir}/firefox" /usr/bin/hptbrowser
			break
		elif [ -f "${dir}/mozilla" ] ; then
			dosym "${dir}/mozilla" /usr/bin/hptbrowser
			break
		elif [ -f "${dir}/htmlview" ] ; then
			dosym "${dir}/htmlview" /usr/bin/hptbrowser
			break
		fi
	done

	domenu "${FILESDIR}/hptwebraid.desktop"
}

pkg_postinst() {
	if [ ! -e /usr/bin/hptbrowser ]; then
		ewarn "Can not find a Web browser which can work with HighPoint Web RAID Management."
		ewarn "Mozilla, Firefox are recommended."
		ewarn "Please link the browser to hptbrowser by command ln."
		ewarn "example: ln -sf /usr/bin/hptbrowser /usr/local/bin/mozilla"
	else
		einfo "Found a Web browser for use with HighPoint Web RAID Management."
		einfo "If you would like to change the browser that was found, link the"
		einfo "browser to hptbrowser by command ln."
		einfo "example: ln -sf /usr/bin/hptbrowser /usr/local/bin/mozilla"
	fi
	echo
	einfo "You need to edit /etc/hptcfg to use the correct driver."
	einfo "Otherwise hptmv6 is the default."
	einfo "Also, you need to have the hptsvr service start at boot time."
	einfo "     rc-update add hptsvr boot"
}

